/***********************************************************
constants
***********************************************************/

const pcIClient = Components.interfaces.pcIClient;

// reference to the required base interface that all components must support
const nsISupports = Components.interfaces.nsISupports;
const CLASS_ID = Components.ID("{6bf44ed5-df65-427a-884e-62e592e18635}");

// description
const CLASS_NAME = "pcClient";

// textual unique identifier
const CONTRACT_ID = "@peercafe.org/pcClient;1";

/***********************************************************
class definition
***********************************************************/

//class constructor
function pcClient() { }

// class definition
pcClient.prototype = {
  localID: "random stranger",

  get localID()   { return this.localID; },
  set localID(id) { return this.localID = id; },

  connect: function() {
    this.log.pcLog("Client connecting...");
  },

  QueryInterface: function(interface_id){
    if (!interface_id.equals(pcIClient) &&    
        !interface_id.equals(nsISupports))
    {
      throw Components.results.NS_ERROR_NO_INTERFACE;
    }
    return this;
  }
};

/***********************************************************
module definition (xpcom beurocracy)
***********************************************************/
var pcClientModule = {
  firstTime: true,

  registerSelf: function(compMgr, fileSpec, loc, type)
  {
    compMgr = compMgr.QueryInterface(
        Components.interfaces.nsIComponentRegistrar);
    compMgr.registerFactoryLocation(
      CLASS_ID, CLASS_NAME, CONTRACT_ID, 
      fileSpec, loc, type);
  },

  unregisterSelf: function(compMgr, loc, type)
  {
    compMgr = compMgr.QueryInterface(
      Components.interfaces.nsIComponentRegistrar);
    compMgr.unregisterFactoryLocation(CLASS_ID, loc);        
  },
  
  getClassObject: function(compMgr, cid, iid)
  {
    if (!cid.equals(CLASS_ID))
      throw Components.results.NS_ERROR_NO_INTERFACE;
    if (!iid.equals(Components.interfaces.nsIFactory))
      throw Components.results.NS_ERROR_NOT_IMPLEMENTED;

    return this.factory;
  },

  canUnload: function(aCompMgr) { return true; },

  /* This function used to generate instances based on the CID. */
  factory:  {
    createInstance: function(outer, iid) {
      if (outer != null)
        throw Components.results.NS_ERROR_NO_AGGREGATION;
      return (new pcClient()).QueryInterface(iid);
    }
  }
};

/***********************************************************
module initialization

Called by the extension manager to find get access to the module defined in
this extension.
***********************************************************/
function NSGetModule(compMgr, fileSpec) { return pcClientModule; }
